package com.dongbo.recorder.screenrecord.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dongbo.recorder.screenrecord.R;
import com.dongbo.recorder.screenrecord.bean.ScreenRecordBean;
import com.dongbo.recorder.screenrecord.utils.DateUtils;

import java.io.File;

/**
 * @author GuoZi
 */
public class VideoAdapter extends BaseQuickAdapter<ScreenRecordBean, BaseViewHolder> {

    private boolean isShowChoose = false;

    public VideoAdapter() {
        super(R.layout.adapter_video);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ScreenRecordBean data) {
        File file = new File(data.getPath());
        Glide.with(getContext()).load(file).into((ImageView) baseViewHolder.getView(R.id.video_icon));
        String date = DateUtils.longToDate(data.getDate());
        baseViewHolder.setText(R.id.video_name, data.getFlieName().replace("0x", "").replace("1x", ""))
                .setText(R.id.video_size, "文件大小:" + data.getSize())
                .setText(R.id.video_date, date);
        if (isShowChoose) {
            baseViewHolder.setGone(R.id.video_choose, false);
        } else {
            baseViewHolder.setGone(R.id.video_choose, true);
        }
        if (data.isChoose()) {
            baseViewHolder.setImageResource(R.id.video_choose, R.mipmap.icon_choose);
        } else {
            baseViewHolder.setImageResource(R.id.video_choose, R.mipmap.icon_unchoose);
        }
        baseViewHolder.setText(R.id.video_time, "录制时间:" + DateUtils.long2ymd(data.getCreatTime()));
    }

    public boolean isShowChoose() {
        return isShowChoose;
    }

    public void setShowChoose(boolean showChoose) {
        isShowChoose = showChoose;
        notifyDataSetChanged();
    }

    //设置选择
    public void setChooseItem(int postion, boolean isChoose) {
        if (postion == -1) {
            for (int i = 0; i < getData().size(); i++) {
                ScreenRecordBean screenRecordBean = getItem(i);
                screenRecordBean.setChoose(isChoose);
                notifyItemChanged(i);
            }
        } else {
            ScreenRecordBean screenRecordBean = getItem(postion);
            screenRecordBean.setChoose(isChoose);
            notifyItemChanged(postion);
        }
    }
}
